package com.bank.service;

import com.bank.entity.Deposit;
import com.bank.repository.DepositRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;

@Service
@Transactional
public class DepositService {
    @Autowired
    private DepositRepository depositRepository;

    public Deposit save(Deposit deposit) {
        return depositRepository.save(deposit);
    }

    public Optional<Deposit> findById(Long id) {
        return depositRepository.findById(id);
    }

    public List<Deposit> findAll() {
        return depositRepository.findAll();
    }

    public void deleteById(Long id) {
        depositRepository.deleteById(id);
    }

    public List<Deposit> findByKeyword(String keyword) {
        // 按存款名称或描述模糊查找
        return depositRepository.findBySavingNameContainingOrDescripContaining(keyword, keyword);
    }

    public List<Deposit> findBySavingID(Long savingID) {
        return depositRepository.findBySavingID(savingID);
    }

    public List<Deposit> findBySavingNameContaining(String savingName) {
        return depositRepository.findBySavingNameContaining(savingName);
    }
} 